package org.zjz.fun.batWord

import java.io.{File, FileInputStream}

import com.fasterxml.jackson.databind.JsonNode
import com.google.common.base.Preconditions.{checkNotNull, checkState}
import org.apache.poi.xwpf.usermodel.XWPFDocument
import org.zjz.BatUtils._
import org.zjz.fun.{BatFun, BattBean}

import scala.collection.mutable.ListBuffer

class WordFun(val filePath:String,val parameter:String) extends BatFun[(String,String),String]{
  private val jsonObject:ListBuffer[JsonNode]=null
  override def readData(in: (String, String)): String = {
 "Sdfsf"
  }
  def transitionMap(): JsonNode ={
     var word= WordFun.readFileWord(filePath)
    null
  }

  def startAnalysis(battAnslysisMap: BattAnslysisMap): Unit ={
     startAnalysis(BattBean(parameter),filePath,battAnslysisMap)
   }
  def startAnalysis(fun:(List[BattBean],XWPFDocument)=>Unit): Unit ={
    startAnalysis(BattBean(parameter),filePath,fun)
  }
   private def startAnalysis(parameter:List[BattBean],word:Any,battAnslysisMap: BattAnslysisMap): Unit ={
     val wordP=WordFun readFileWord word
     battAnslysisMap.mapParagraphs(parameter,wordP)
  }
  private def startAnalysis(parameter:List[BattBean],word:Any,fun:(List[BattBean],XWPFDocument)=>Unit): Unit ={
    val wordP=WordFun readFileWord word
    fun(parameter,wordP)
  }
  def wordMap(): Unit ={

  }
}
object WordFun{
  private def readAny:PartialFunction[Any,File]={
    case x:String=>new File(x)
    case f:File=>f
    case _=>throw new IllegalArgumentException
  }
  private def readFileWord(any: Any): XWPFDocument ={
    val file=readAny(any)
    checkNotNull(file,"%s","没有找到此文件")
    var checkParameter=fileType(file.getPath,Array("docx"))
    checkState(checkParameter _2,"%s",s"文件类型不正确${checkParameter _1}")
    var inStream=new FileInputStream(file)
    new XWPFDocument(inStream)
  }

}